package com.lanou3g.hw0514.view;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by dllo on 18/5/15.
 */
//通过request域存值,将msg的值在Msg中使用即可(只有同义词请求可以使用request域,即重定向不能使用request域)
@WebServlet(name = "MsgServlet", urlPatterns = "/msg")
public class MsgServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //通过key取值,这个key必须是存值的时候,使用的key
        String msg = (String) request.getAttribute("msg");
        //request域 的三个方法:getAttribute取值,setAttribute取值,removeAttribute删值
        response.getWriter().println(msg);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
